/**
 * Created by hjqi on 2016/2/5.
 */

var Base = require('./oauth_base');
var util = require('util');
var crypto = require('crypto');
var oauthConf = require('../config/config').oauth2;
module.exports = bitbucketOauth2;
function bitbucketOauth2() {
    /*this._opt = {
     "client_id":"cLXYuCSL5zpaJsqQf7",
     "secret":"u32nFrZTXCqJRvnYTK6LeXTMXrpjcZ2L",
     "baseurl":"https://bitbucket.org/",
     "authorize_url":"site/oauth2/authorize",
     "token_url":"site/oauth2/access_token",
     "callback_url":"http://test.168home.net:8899/bitbucket"
     }*/
    this._opt = oauthConf.bitbucket;
    this._accessTokenParam  = {
        grant_type:'authorization_code'
    }
    Base.call(this);
}

bitbucketOauth2.prototype.getReqAuthUrlAndSt = function(){
    var _st = crypto.randomBytes(32).toString('hex');
    var _url =  this._oauth2.getAuthorizeUrl({
        response_type:'code',
        state:_st
    });
    return {
        st:_st,
        url:_url
    }
}

util.inherits(bitbucketOauth2,Base);